
<?php require ('./order.php'); ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>排名</title>
 <link href="css/jquery-ui.min.css" rel="stylesheet" type="text/css">
    <link href="css/xlstablefilter.css" rel="stylesheet" type="text/css">
    <link href="css/gl.css" rel="stylesheet" type="text/css">
    <script src="selectuser.js"></script>
    <script src="js/jquery.min.js"></script>
    <script src="js/jquery-ui.min.js"></script>
    <script type="text/javascript" src="js/jquery.xlstablefilter.js"></script>
  
    <script type="text/javascript" src="jquery.js"></script>
    </script>
<script src="/jquery/jquery-1.11.1.min.js">
</script>
<script>
    //将form转为AJAX提交
    function ajaxSubmit(frm, fn) {
        var dataPara = getFormJson(frm);
        $.ajax({
            url: frm.action,
            type: frm.method,
            data: dataPara,
            success: fn
        });
    }

    //将form中的值转换为键值对。
    function getFormJson(frm) {
        var o = {};
        var a = $(frm).serializeArray();
        $.each(a, function() {
            if (o[this.name] !== undefined) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
    return o;
    }
    //调用
    $(document).ready(function(){
        $('#Form1').bind('submit', function(){
            ajaxSubmit(this, function(data){
                alert(data);
            });
            return false;
        });
        
        $('#Form2').bind('submit', function(){
            ajaxSubmit(this, function(data){
                alert(data);
            });
            return false;
        });
    });
    </script>

</head>    
<style>
.div-relative{margin-left: auto;margin-right: auto;text-align:center;position:relative; color:#000; height:3000px} 
.div-a{ position:absolute; left:30px; background:#ffffff} 
/* css注释说明： 背景为红色 */ 

.div-c{ position:absolute;top: 1px; background:#ffffff;height:1500px;width: 2500px;visibility: hidden}
#ff{
  position: relative;
  top:250px;
  left: 500px;
  width: 200px;
  height: 200px;
} 
</style>  
<?php  
session_start();  
//echo $_SESSION['Role'];
//echo $_SESSION['Pleader'];
?>
<body  onbeforeunload="window.location='logout.php'">
<?php 
$Pleader=$_SESSION['Pleader'];
$Role = $_SESSION['Role'];

$rows= array();
$row3= array();
$row5= array();
$sqlllll="select * from AX_replace_col_options where Col='U_OrderId' ";
$arr6=odbc_exec($sqlconnection,$sqlllll);
while($rowwww=odbc_fetch_array($arr6)){
$row5[]=$rowwww;
}
$sqll="select * from AX_replace_col_options where Col='U_RepalceType'";
$arr3=odbc_exec($sqlconnection,$sqll);
while($row=odbc_fetch_array($arr3)){
$rows[]=$row;
}
$sqlll="select * from AX_Replace_Users where Role='Susers'";
$arr4=odbc_exec($sqlconnection,$sqlll);
while($roww=odbc_fetch_array($arr4)){
$row3[]=$roww;
}
 odbc_close($sqlconnection);
$sqlquery="select T0.[RelatedTable],T0.[RelatedColumn],T1.Description from [dbo].[AX_Replace_Role_Right] T0 left join [dbo].[AX_Order_Column_Display] T1 ON T0.[RelatedTable]=T1.[RelatedTable] AND
T0.[RelatedColumn]=T1.[RelatedColumn] WHERE T0.[role]='".$Role."' and T0.IsVisable='Y' and T0.[RelatedTable]='AX_replace_order' order by visorder";
$datelist=array();
$title="";
//echo $sqlquery;
$arr=odbc_exec($sqlconnection,$sqlquery); 
$sqlmid='';
$sqlleft='Select 0';
// 使用while语句循环mysql_fetch_array()函数返回的数组
while($result=odbc_fetch_array($arr)){
$sqlmid=$sqlmid.','.$result['RelatedColumn'];
$title=$title."
<th>".iconv("GB18030//IGNORE","utf-8",$result['Description'])."</th>";
$colid[]=$result['RelatedColumn'];
}

$sqlright=" from AX_replace_order where U_OStatus='1' and  ( U_PManager = '".$_SESSION['Pleader']."' OR U_PManager='' OR U_PManager is null) and U_CardName  LIKE '".iconv('utf-8','GB18030//IGNORE',"%积分%")."'";
$ownsql=$sqlleft.$sqlmid.$sqlright;
//ECHO $ownsql;
$arr2=odbc_do($sqlconnection,$ownsql);
$mx=count($colid);

//echo $title;
//print_r($rows);
?>
<center>
<div class="div-relative"> 
<div class="div-a">
<form id="Form1" name="contact" action="add.php" method="POST">
<table id="example1" class="tblGrid">
<thead>
       <tr>
        <td ><label  /></td> 
           <td ><label  /></td> 
            <td ><label /></td> 
             <td ><label  /></td> 
              <td ><label></label></td> 
               <td ><label /></td> 
               <td ><label /></td> 
               <td ><label  /></td> 
               <td ><label  /></td> 
                <td ><label  /></td> 
<?php 
echo "<td>";
echo "<select name='name2' onchange='c2(this)' id='dd'>"; 
echo '<option></option>';
  echo '<option value="1">未处理</option>';
  echo '<option value="3">待处理</option>';
echo "</select>";
echo "</td>";
?>                
<?php 
echo "<td>";
echo "<select name='name' onchange='c(this)' id='bb'>"; 
echo '<option></option>';
  echo '<option value="D3">小仓</option>';
  echo '<option value="D1">大仓</option>';
  echo '<option value="D2">大仓加料</option>';
echo "</select>";
echo "</td>";
?>
<?php 
echo "<td>";
echo "<select name='name1' onchange='c1(this)' id='cc'>";
echo "<option />";  
for($i=0;$i<count($row3);$i++){
echo '<option value="'.$row3[$i]['UserName'].'">'.iconv("GB18030","utf-8//IGNORE",$row3[$i]['UserName']).'</option>';
}
echo "</select>";
echo "</td>";

?> 

 <td width="20"><input onclick="selectAll(this)" type="checkbox"></td>
 <td><input type='button' name='allbutton' onclick='getCellValue()' value='全部提交' /></td>
</tr>       

<?php echo "<tr>";
echo $title;
echo "</tr>";
echo "</thead>";
echo "<tbody>";
$LINEID=0;
//echo $contents;
while($result2=odbc_fetch_array($arr2)){
$LINEID++;
echo "<tr>";   
for($x=0;$x<$mx;$x++) {

if($colid[$x]=="U_DocDate"){
echo "<td>".substr($result2[$colid[$x]], 0,10)."</td>";
}

if($colid[$x]=="U_OrderId"){
echo "<td><input id ='aa".$LINEID."' value='".$result2[$colid[$x]]."' readonly></input></td>";
}

if($colid[$x]=="U_OStatus"){
  echo "<td>";
  echo "<select name='name2' id='sta".$LINEID."'>"; 
  echo '<option value="1">未处理</option>';
  echo '<option value="3">待处理</option>';
  echo "</select>";
  echo "</td>";
}

//***//
if($colid[$x]=="U_CardName"){
  
echo "<td>".iconv("GB18030","utf-8//IGNORE",$result2[$colid[$x]])."</td>";
 
}

if($colid[$x]=="U_ItemCode"){
  echo "<td id='itemcode".$LINEID."' >".$result2[$colid[$x]]."</td>";
}
if($colid[$x]=="U_CitemCd"){
  echo "<td id='itemcd".$LINEID."' >".$result2[$colid[$x]]."</td>";
}

//**//
if($colid[$x]=="U_CitemNm"){
  echo "<td title='".iconv("GB18030","utf-8//IGNORE",$result2[$colid[$x]])."'>".iconv("GB18030","utf-8//IGNORE",$result2[$colid[$x]])."</td>";
}

if($colid[$x]=="U_Qty"){
    echo "<td>";
  echo $result2[$colid[$x]];
  echo "</td>";
}
if($colid[$x]=="U_State"){
   echo "<td width='20px'>".iconv("GB18030","utf-8//IGNORE",substr($result2[$colid[$x]], 0,4))."</td>";
 
}


if($colid[$x]=="U_PManager"){
  echo "<td>".iconv("GB18030","utf-8//IGNORE",substr($result2[$colid[$x]], 9,13))."</td>";
}
if($colid[$x]=="U_brand"){
  echo "<td>".iconv("GB18030","utf-8//IGNORE",$result2[$colid[$x]])."</td>";
}
if($colid[$x]=="RepalceType"){
  echo "<td>";
  echo "<select name='name' id='status".$LINEID."'>"; 
  echo '<option value="D3">小仓</option>';
  echo '<option value="D1">大仓</option>';
  echo '<option value="D2">大仓加料</option>';
  echo "</select>";
  echo "</td>";

}
if($colid[$x]=="Susers"){
echo "<td>";
echo "<select name='name1' id='susers".$LINEID."'>";
echo "<option />";
for($i=0;$i<count($row3);$i++){

echo '<option value="'.$row3[$i]['UserName'].'">'.iconv("GB18030","utf-8//IGNORE",$row3[$i]['UserName']).'</option>';
}
echo "</select>";
echo "</td>";

}

}
echo "<td>";
echo "<input type='checkbox' name='check[]' id='checkbox".$LINEID."' />";
echo "</td>";
echo "<td>";
echo "<input type='button' name='button' onclick='getRowNo(this)' value='提交' />";
echo "</td>";
}


?>
</tbody>
</table>

</form>

</div>

<div class="div-c" id="div-c">

<img id="ff" src="./images/img.gif"/>


</div> 
</center>
    <script type="text/javascript">

    $(function() {
      $("#example1").xlsTableFilter();
    });
    </script>
<script type="text/javascript">
function getRowObj(kk)
{   var k = 0;   
while(kk.tagName.toLowerCase() != "tr")
{kk = kk.parentNode;    
if(kk.tagName.toLowerCase() == "table")
return null;   
}   
return kk;
}
//根据得到的行对象得到所在的行数
function getRowNo(kk)
{
var trObj = getRowObj(kk);    
var trArr = trObj.parentNode.children; 
for(var trNo= 0; trNo < trArr.length; trNo++)
{if(trObj == trObj.parentNode.children[trNo])
{i=trNo+1; 
//var i=trNo+1;
//if($RepalceType='D2'||$RepalceType='D3'&&$Susers!=''){

  var selects='susers'+i;
  var x=document.getElementById(selects);
  $a=x.options[x.selectedIndex].value;
  //alert($a);

  var status='status'+i;
  var y=document.getElementById(status);
  $b=y.options[y.selectedIndex].value;

  var orid='aa'+i;
  var z=document.getElementById(orid);
  $d=z.value;

  var mm='sta'+i;
  var p=document.getElementById(mm);
  $s=p.value;
//***//
  var item='itemcode'+i;
  var f=document.getElementById(item).innerHTML;
  $h=f;
  //alert($h);

   var items='itemcd'+i;
  var ff=document.getElementById(items).innerHTML;
  $hh=ff;
 //alert($hh);
  $c=$d+$b+$a+$s+$hh+$h;
  //alert($c);
//***//
  $.post("padd.php",
    {
      U_ItemCode:$h,
      U_CitemCd:$hh,
      U_OrderId:$d,
      Susers:$a, 
      RepalceType:$b,
      U_OStatus:$s,
      U_Operator:"<?php echo $_SESSION['UserName'];?>"
    },
    function(data,status){
      //alert("数据：" + data + "\n状态：" + status);
    });
    }
   // else{
      //alert("提交失败,仓位不能为空.");
   // }
   //} 
 }
}
</script>
<script type="text/javascript">
function getRowObj(kk)
{   var k = 0;   
while(kk.tagName.toLowerCase() != "tr")
{    kk = kk.parentNode;    
if(kk.tagName.toLowerCase() == "table")
return null;   
}   
return kk;
}

function getCellValue()
{
  if(window.confirm("确认提交吗?")) {


document.getElementById("div-c").style.visibility="visible";
var rows = document.getElementById("example1").rows;
var a = document.getElementsByName("check[]");
//var states = "";
var  table = document.getElementById("example1");
//alert("start");

var  table = document.getElementById("example1");
var arrays = new Array(); 
          var items = document.getElementsByName("check[]");
          for(var i=0;i<items.length;i++){
              if(items[i].checked){
                  arrays.push(items[i].value);
              }
          }
          var xx=arrays.length;
          var div1=document.getElementById("div-c");
var op=xx*3000;
//alert(op);
function reloadd(){
 window.location.reload();
}setTimeout(reloadd,op);
function hide(){
  div1.style.display="none";
}setTimeout(hide,op);

          //alert(arrays.length);

//alert(xx);

for(var i=0;i<a.length;i++)
{
if(a[i].checked){
var row = a[i].parentElement.parentElement.rowIndex;
//states += rows[row].cells[1].innerHTML+";";
  //alert(a[i].id);
   j= i+1;
  //alert(p);
//var i=trNo+1;
  var selects='susers'+j;
  var x=document.getElementById(selects);
  $a=x.options[x.selectedIndex].value;
  
  var status='status'+j;
  var y=document.getElementById(status);
  $b=y.options[y.selectedIndex].value;

  var orid='aa'+j;
  var z=document.getElementById(orid);
  $d=z.value;

  var mm='sta'+j;
  var p=document.getElementById(mm);
  $s=p.value;

 var item='itemcode'+j;
  var f=document.getElementById(item).innerHTML;
  $h=f;
  //alert($h);

   var items='itemcd'+j;
  var ff=document.getElementById(items).innerHTML;
  $hh=ff//;
 //alert($hh);
  $c=$d+$b+$a+$s+$hh+$h;
  //alert($c);

 $.post("padd.php",
    { 
      U_CitemCd:$hh,
      U_ItemCode:$h,
      U_OrderId:$d,
      Susers:$a, 
      RepalceType:$b,
      U_OStatus:$s,
      U_Operator:"<?php echo $_SESSION['UserName'];?>"
    },
    function(data,status){
      //alert("数据：" + data + "\n状态：" + status);
    });
   } 
 }


}
  else{
    window.location = "#";
  }

 //alert("end");
 // location.reload(); 
}  
</script>
<script type="text/javascript">
$("#rr").blur(function){
    $.post("Server路径",{name:$(this).val()},function(data)){
 }
}
</script>


<script>
   function selectAll(obj)
      {
        var cbList = document.getElementsByName("check[]");
        for(var i=0;i < cbList.length;i++)
        {
          if(cbList[i].className.indexOf('disable')===-1){
            if(obj.checked)
            {
                cbList[i].checked=true;
            }
            else
            {
                cbList[i].checked=false;
            }
          }
          
        }
      }
function c(obj) {
            $("select").each(function () {
                $(this).val($(obj).val());
            });
        } 
function c() 
{
var rows = document.getElementById("example1").rows; 
var a = document.getElementsByName("check[]"); 
var  table = document.getElementById("example1");
var inputs = document.getElementsByName("name");
var ex=0;       

for(var i=0;i<a.length;i++) 
{ 
if(a[i].checked){ 
var row = a[i].parentElement.parentElement.rowIndex; 
  ex=row-1;
  inputs[ex].value=document.getElementById("bb").value;
} 
}
} 
function c1() 
{
var rows = document.getElementById("example1").rows; 
var a = document.getElementsByName("check[]"); 
var  table = document.getElementById("example1");
var inputs = document.getElementsByName("name1");
var ex=0;       

for(var i=0;i<a.length;i++) 
{ 
if(a[i].checked){ 
var row = a[i].parentElement.parentElement.rowIndex; 
  ex=row-1;
  inputs[ex].value=document.getElementById("cc").value;
} 
}
}     
function c2() 
{
var rows = document.getElementById("example1").rows; 
var a = document.getElementsByName("check[]"); 
var  table = document.getElementById("example1");
var inputs = document.getElementsByName("name2");
var ex=0;       

for(var i=0;i<a.length;i++) 
{ 
if(a[i].checked){ 
var row = a[i].parentElement.parentElement.rowIndex; 
  ex=row-1;
  inputs[ex].value=document.getElementById("dd").value;
} 
}
}  
</script>
    </div>
</body>
</html>